home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
001a
/
dde_10.zip
/
DDE.C
next >
Wrap
Text File
|
1991-03-01
|
29KB
|
722 lines
/* Standard Library include files */
#include <search.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <memory.h>
#include <dos.h>
/* TCXL Library includes */
#include <tcxldef.h>
#include <tcxlsel.h>
#include <tcxlkey.h>
#include <tcxlwin.h>
#include <tcxlvid.h>
#include <tcxlkey.h>
#include <tcxlcod.h>
#include <tcxlmou.h>
/*
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓ ▓▓
▓▓ Structure for PROCOMM PLUS dialing directory entry. ▓▓
▓▓ ▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
from the hook.c file that comes with procomm plus 2.0
*/
typedef struct DDREC
{
char ddname[25], /* name */
ddphone[21]; /* phone number */
int ddbaud; /* baud rate as int */
char ddparity, /* parity as short int */
dddata, /* data bits as short int */
ddstop, /* stop bits as short int */
dddup, /* duplex as short int: 0 = full */
ddscript[9], /* ASPECT file w/o ext */
ddlast[9]; /* last call: mm/dd/yy */
int ddtotal; /* total connects */
char ddproto, /* default protocol as short int */
ddterm, /* terminal type as short int */
ddmode, /* 0 = mode, 1 = direct */
ddpassword[11], /* like it says */
ddmacfile[9], /* keyboard macro file */
ddkbdfile[9], /* keyboard mapping file */
ddport, /* com port to use */
ddnotefile[9]; /* note file */
} dd_entry;
#define DD_SIZE 200 /* size of the dialing directory with pcplus 2.0 */
/*
*
* Name: main()
*
* Useage: called from o/s
*
* Parameters: none
*
* Returns: exits with errorlevel set to 0 if no problems occur
*
* Function: main routine of PCPlus Dialing Directory Editor.
*
* Written by: David Gersic 27 Feb 1991
*
*/
void
main()
{
/* variables */
dd_entry *dial_dir, /* old and new dialing directories */
*dial_new;
char header[250], /* header in dialing directory file */
*in_file, /* input file name */
out_file[13]; /* output file name */
/* functions */
int read_ddir(char *, dd_entry *, char *),
write_ddir(char *, dd_entry *, char *),
modify_ddir(dd_entry *,dd_entry *);
char *get_in_file(void);
int get_out_file(char *);
TcxlInit(); /* initialize library */
VcurHid(0); /* turn off cursor */
Wopen(0,0,24,79,BOX_SPA,LGREY | _RED,LGREY | _RED); /* main window */
/* set up title and credits */
Wgotoxy(24,0);
Wputs(" David Gersic 17 Feb. 1991");
Wopen(0,0,23,79,BOX_HOR,LGREY | _RED,LGREY | _RED);
Wtitle(" ProcommPlus 2.0 Dialing Directory Editor v1.0 ",TTL_CNT,YELLOW|_RED);
while(in_file=get_in_file()) /* get input file name */
{ /* loop terminates when <esc> is pressed */
if((dial_dir=(dd_entry *)malloc((DD_SIZE)*sizeof(dd_entry))) == NULL)
{
fprintf(stderr,"Malloc failed.\nExiting to DOS.\n");
exit(1);
}
if((dial_new=(dd_entry *)malloc((DD_SIZE)*sizeof(dd_entry))) == NULL)
{
fprintf(stderr,"Malloc failed.\nExiting to DOS.\n");
exit(1);
}
read_ddir(in_file,dial_dir,header); /* read in dialing directory */
modify_ddir(dial_dir,dial_new); /* re-arrange directory */
Wclose(); /* close edit windows */
Wclose();
if(get_out_file(out_file)==0) /* get output file name */
write_ddir(out_file,dial_new,header); /* write out new dir */
free(dial_dir); /* free dynamic memory */
free(dial_new);
}
WcloseAll(); /* close all windows and exit */
VcurHid(1);
exit(0);
} /* end main() */
/*
*
* Name: read_ddir()
*
* Useage: read_ddir(char *dd_name, dd_entry *dial_dir, char *header)
*
* Parameters: char *dd_name filename of directory file to read in
* dd_entry *dial_dir where to put directory read in
* char *header where to store header
*
* Returns: 0
*
* Function: To read in a ProcommPlus 2.0 dialing directory file.
*
* Written by: David Gersic 27 Feb 1991
*
*/
int
read_ddir(char *dd_name, dd_entry *dial_dir, char *header)
{
FILE *dd_file;
int i=0;
dd_file=fopen(dd_name,"rb"); /* open file for input, no translation */
if(dd_file==NULL) /* file not open */
{
fprintf(stderr,"Error opening input file.\nExiting to DOS.\n");
exit(1);
}
fread(header,250,1,dd_file); /* read header */
while(i<DD_SIZE) /* read dialing directory entries */
{
if(fread((dial_dir+i),114,1,dd_file) != 1) /* one at a time */
{
if(ferror(dd_file)) /* error reading file */
perror("Error reading file.\n");
else
fprintf(stderr,"Unknown error reading file.\n");
fprintf(stderr,"Aborting!\n");
exit(1); /* abort to DOS */
}
i++;
}
fclose(dd_file);
return(0);
} /* end read_ddir() */
/*
*
* Name: write_ddir()
*
* Useage: write_ddir(char *dd_name, dd_entry *dial_dir, char *header)
*
* Parameters: char *dd_name filename to write out to
* dd_entry *dial_dir memory image of directory to write out
* char *header header saved by read_ddir()
*
* Returns: 0
*
* Function: To write out a ProcommPlus 2.0 dialing directory read in by
* read_ddir().
*
* Written by: David Gersic 27 Feb 1991
*
*/
int
write_ddir(char *dd_name, dd_entry *dial_dir, char *header)
{
FILE *out_file;
int i=0;
out_file=fopen(dd_name,"wb"); /* open file, no translation */
if(out_file==NULL) /* file not open */
{
fprintf(stderr,"Error opening output file.\nExiting to DOS.\n");
exit(1);
}
fwrite(header,250,1,out_file); /* write header */
while(i<DD_SIZE) /* write dialing directory entries */
{
if(fwrite((dial_dir+i),114,1,out_file) != 1) /* one at a time */
{
if(ferror(out_file)) /* error writing to file */
perror("Error writing file.\n");
else
fprintf(stderr,"Unknown error writing file.\n");
fprintf(stderr,"Aborting!\n");
exit(1); /* exit to o/s */
}
i++;
}
fclose(out_file);
return(0);
} /* end write_ddir() */
/*
*
* Name: get_in_file()
*
* Useage: get_in_file()
*
* Parameters: none
*
* Returns: pointer to the filename to be opened.
*
* Function: To get a filename from a pick-list. It passes the name back
* to the caller.
*
* Written by: David Gersic 27 Feb 1991
*
*/
char *
get_in_file()
{
char *file_name;
VOID CTYP AddShadow(NOARG); /* add drop-shadow to open window */
Wgotoxy(2,24); /* text prompt on screen */
WsetTxt(WHITE | _RED);
Wputf("Dialing Directory To Modify.");
file_name=SelFile(5,30,20,43,BOX_HOR,LGREY|_BLUE,LGREY|_BLUE,BLUE|_LGREY,0,"*.DIR",AddShadow);
Wclear();
return(file_name);
} /* end get_in_file() */
/* very small function, called to add a shadow to a window */
VOID CTYP
AddShadow(NOARG)
{
Wshadow(LGREY|_BLACK);
}
/*
*
* Name: get_out_file()
*
* Useage: get_out_file(char *out_file)
*
* Parameters: char *out_file where to put the filename
*
* Returns: 0
*
* Function: To get a filename input from the user. It only allows
* eight characters to be input, and forces the extention
* to be ".dir". I couldn't find a way to disallow the '.'
* character in the input string, so I just strip anything
* after a '.' and tack on a '.dir'. Sort of a kludge, but
* it works.
*
* Written by: David Gersic 27 Feb 1991
*
*/
int
get_out_file(char *out_file)
{
int i=0;
if(MouInit) /* if mouse has been found */
{
MouLvl=MOU_KEYS; /* allow mouse click for <esc> and <ret> keys */
}
VcurHid(1); /* turn on cursor for text input */
Wgotoxy(13,13); /* screen prompts */
WsetTxt(WHITE|_RED);
Wputf("Filename with no extention. <Esc> to abort changes.");
Wopen(9,15,11,64,BOX_HOR,LGREY | _BLUE,LGREY | _BLUE);
Wshadow(LGREY|_BLACK);
Wgotoxy(0,0);
WsetTxt(WHITE | _BLUE);
if(KwGetFmt(out_file, "' Save into <filename>? ' !CUR! F!R!FFFFFFF")!=ERR_NUL)
{ /* esc key pressed */
VcurHid(0); /* hide cursor again, close window and return */
Wclose();
Wclear();
return(1);
}
else /* filename typed in */
{
while(i<8) /* strip extention off */
{
i++;
if( *(out_file+i) == '.')
*(out_file+i)='\0';
}
VcurHid(0);
strcat(out_file,".DIR"); /* put on ".dir" */
Wclose(); /* close window and return */
Wclear();
return(0);
}
} /* end get_out_file() */
/*
*
* Name: modify_ddir()
*
* Useage: modify_ddir(dd_entry *dial_dir,dd_entry *dial_new)
*
* Parameters: dd_entry *dial_dir dialing directory image to modify
* dd_entry *dial_new where to put the new directory
*
* Returns: 0
*
* Function: This is the function that does all of the "work". User input
* is taken from either keyboard or mouse, and processed. The
* new dialing directory is built from the old one, and
* modifications are shown on the screen in a window. Very little
* error checking is done, but the code is fairly robust so
* no errors "should" occur.
*
* Written by: David Gersic 27 Feb 1991
*
*/
int
modify_ddir(dd_entry *dial_dir,dd_entry *dial_new)
{
dd_entry *index[DD_SIZE], /* arrays of pointers to set up indexes */
*new[DD_SIZE]; /* into the real copies of the dialing directories */
WndT new_win, /* window "handle"s */
old_win;
KeyT in_key=0; /* keyboard input variable */
int i, /* scratch */
new_ndx=0, /* index variables into index arrays */
old_ndx=0,
new_lin=0,
old_lin=0;
/* set up screen */
new_win=Wopen(1,41,21,75,BOX_HOR,LGREY | _BLUE,LGREY | _BLUE);
Wtitle(" Destination ",TTL_CNT,YELLOW|_BLUE);
Wshadow(LGREY|_BLACK);
Wbprintc(BRD_RGT,1,WHITE|_BLUE,'');
Wbprintc(BRD_RGT,19,WHITE|_BLUE,'');
old_win=Wopen(1,2,21,36,BOX_HOR,LGREY | _BLUE,LGREY | _BLUE);
Wtitle(" Source ",TTL_CNT,YELLOW|_BLUE);
Wshadow(LGREY|_BLACK);
Wbprintc(BRD_RGT,1,WHITE|_BLUE,'');
Wbprintc(BRD_RGT,19,WHITE|_BLUE,'');
/* set up pointers to array entries */
for(i=0;i<DD_SIZE;i++)
{
index[i]=(dial_dir+i);
new[i]=NULL; /* display entries on "old" half of screen */
if(i<19) /* room for 19 entries on screen at a time */
Wputf(" %3d %s\n",i+1,index[i]->ddname); /* display entry */
}
if(MouInit) /* if mouse was found */
{
MShome(); /* home mouse cursor */
MSlimit(2,2,20,75); /* set on-screen limit on movement */
MouLvl=MOU_CURS; /* set level of support */
MSshow(); /* show mouse cursor */
MouBtn=0; /* intitialize variable */
}
/* put up "blank" new window and number lines */
Wactiv(new_win);
for(i=1;i<20;i++)
Wputf(" %3d\n",i);
KeyClear(); /* clear keyboard buffer */
Wactiv(old_win);
do { /* main body of loop */
Wgotoxy(old_lin,2); /* highlight current "old" entry */
WsetTxt(BLUE | _LGREY);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
while(!KeyEvent()); /* spin until . . . */
if(MouBtn & 0x01) /* if event was mouse click */
{ /* which side of screen was it on */
if(MouCol > 2 && MouCol <= 36) /* left hand window, old dir */
{
Wgotoxy(old_lin,2); /* highlight off */
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
if(MouRow==2 && MouCol==36) /* scroll up arrow */
{
WscrWin(1,DIR_DWN);
Wgotoxy(0,2);
if(old_ndx-old_lin-1 < 0)
Wputf("%3d %-25s",old_ndx-old_lin+200,index[old_ndx-old_lin+199]->ddname);
else
Wputf("%3d %-25s",old_ndx-old_lin,index[old_ndx-old_lin-1]->ddname);
old_lin=(old_lin+1);
if(old_lin > 18)
{
old_ndx--;
if(old_ndx<0)
old_ndx=199;
old_lin=18;
}
_Delay(1); /* slight delay, slow it down */
}
else if(MouRow==20 && MouCol==36) /* scroll down arrow */
{
WscrWin(1,DIR_UP);
Wgotoxy(18,2);
Wputf("%3d %-25s",((old_ndx-old_lin+19)%200)+1,index[(old_ndx-old_lin+19)%200]->ddname);
old_lin=old_lin-1;
if(old_lin < 0)
{
old_ndx=(old_ndx+1)%200;
old_lin=0;
}
_Delay(1); /* slow down screen scroll */
}
else /* within window, set new "current" pointer */
{
old_ndx=(old_ndx-old_lin+MouRow-2)%200;
if(old_ndx<0)
old_ndx+=200;
old_lin=MouRow-2;
}
}
else if(MouCol > 41 && MouCol <=75) /* right hand window */
{
Wactiv(new_win); /* switch active window */
if(MouRow==2 && MouCol==75) /* scroll up arrow */
{
WscrWin(1,DIR_DWN);
Wgotoxy(0,2);
if(new_ndx-new_lin-1 < 0)
if(new[new_ndx-new_lin+199]==NULL)
Wputf("%3d %-25s",new_ndx-new_lin+200," ");
else
Wputf("%3d %-25s",new_ndx-new_lin+200,new[new_ndx-new_lin+199]->ddname);
else
if(new[new_ndx-new_lin-1]==NULL)
Wputf("%3d %-25s",new_ndx-new_lin," ");
else
Wputf("%3d %-25s",new_ndx-new_lin,new[new_ndx-new_lin-1]->ddname);
new_lin=(new_lin+1);
if(new_lin > 18)
{
new_ndx--;
if(new_ndx<0)
new_ndx=199;
new_lin=18;
}
}
else if(MouRow==20 && MouCol==75) /* scroll down arrow */
{
WscrWin(1,DIR_UP);
Wgotoxy(18,2);
if(new[(new_ndx-new_lin+19)%200]==NULL)
Wputf("%3d %-25s",((new_ndx-new_lin+19)%200)+1," ");
else
Wputf("%3d %-25s",((new_ndx-new_lin+19)%200)+1,new[(new_ndx-new_lin+19)%200]->ddname);
new_lin=new_lin-1;
if(new_lin < 0)
{
new_ndx=(new_ndx+1)%200;
new_lin=0;
}
}
else /* click in window, put new entry */
{
new_ndx=(new_ndx+MouRow-2-new_lin);
if(new_ndx < 0)
new_ndx+=200;
if(new_ndx == 200)
new_ndx=0;
new_ndx=new_ndx%200;
new[new_ndx]=index[old_ndx];
new_lin=MouRow-2;
Wgotoxy(new_lin,2);
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",new_ndx+1,index[old_ndx]->ddname);
_Delay(2); /* slight delay */
}
Wactiv(old_win); /* reactivate "old" window */
}
MouBtn=0; /* re-initialize button variable */
}
else if(MouBtn & 0x02) /* right button */
{
MouBtn=0;
break; /* treat right button as <esc> */
}
else /* must have been a keypress */
{
in_key=KeyGetc(); /* get keyboard input */
switch (in_key) { /* process . . . */
case Key_Up:
Wgotoxy(old_lin,2);
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
old_ndx--;
if(old_ndx<0)
old_ndx=199;
old_lin--;
if(old_lin<0)
{
WscrWin(1,DIR_DWN);
old_lin=0;
}
break;
case Key_Dwn:
Wgotoxy(old_lin,2);
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
old_ndx=(old_ndx+1) % 200;
old_lin++;
if(old_lin>18)
{
WscrWin(1,DIR_UP);
old_lin=18;
}
break;
case Key_PgDn:
Wgotoxy(old_lin,2);
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
old_ndx=old_ndx+18-old_lin; /* added -old_lin */
if(old_ndx>199)
old_ndx-=199;
old_lin=0;
/* redraw screen */
Wclear();
for(i=0;i<19;i++)
{
Wgotoxy(i,2);
Wputf("%3d %-25s",((old_ndx+i)%200)+1,index[(old_ndx+i)%200]->ddname);
}
break;
case Key_PgUp:
Wgotoxy(old_lin,2);
WsetTxt(LGREY | _BLUE);
Wputf("%3d %-25s",old_ndx+1,index[old_ndx]->ddname);
old_ndx=old_ndx-18-old_lin; /* added -old_lin */
if(old_ndx<0)
old_ndx+=199;
old_lin=0;
/* redraw screen */
Wclear();
for(i=0;i<19;i++)
{
Wgotoxy(i,2);
Wputf("%3d %-25s",((old_ndx+i)%200)+1,index[(old_ndx+i)%200]->ddname);
}
break;
case Key_Ent: /* switch windows and put current old_entry at selected new_entry */
Wactiv(new_win);
Wgotoxy(new_lin,2);
WsetTxt(BLUE | _LGREY); /* highlight bar */
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
do { /* get keyboard input to select new entry to fill */
in_key=KeyGetc();
Wgotoxy(new_lin,2);
WsetTxt(LGREY | _BLUE); /* highlight off */
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
switch(in_key) { /* process keystroke */
case Key_Up:
new_ndx--;
new_lin--;
if(new_lin<0)
{
WscrWin(1,DIR_DWN);
new_lin=0;
}
if(new_ndx<0)
new_ndx=199;
break;
case Key_Dwn:
new_ndx=(new_ndx+1)%200;
new_lin++;
if(new_lin>18)
{
WscrWin(1,DIR_UP);
new_lin=18;
}
break;
case Key_PgDn:
Wgotoxy(new_lin,2);
WsetTxt(LGREY | _BLUE);
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
new_ndx=new_ndx+18-new_lin;
if(new_ndx>199)
new_ndx-=199;
new_lin=0;
/* redraw screen */
Wclear();
for(i=0;i<19;i++)
{
Wgotoxy(i,2);
if(new[(new_ndx+i)%200]==NULL)
Wputf("%3d %-25s",((new_ndx+i)%200)+1," ");
else
Wputf("%3d %-25s",((new_ndx+i)%200)+1,new[(new_ndx+i)%200]->ddname);
}
break;
case Key_PgUp:
Wgotoxy(new_lin,2);
WsetTxt(LGREY | _BLUE);
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
new_ndx=new_ndx-18-new_lin;
if(new_ndx<0)
new_ndx+=199;
new_lin=0;
/* redraw screen */
Wclear();
for(i=0;i<19;i++)
{
Wgotoxy(i,2);
if(new[(new_ndx+i)%200]==NULL)
Wputf("%3d %-25s",((new_ndx+i)%200)+1," ");
else
Wputf("%3d %-25s",((new_ndx+i)%200)+1,new[(new_ndx+i)%200]->ddname);
}
break;
} /* end switch */ /* new line selected */
Wgotoxy(new_lin,2);
WsetTxt(BLUE | _LGREY); /* highlight new current entry */
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
} while (in_key!=Key_Ent && in_key!=Key_Esc); /* loop until ... */
Wgotoxy(new_lin,2);
WsetTxt(LGREY | _BLUE); /* in "normal" attributes */
if(in_key!=Key_Esc) /* if <return>, update "new" index */
{
Wputf("%3d %-25s",new_ndx+1,index[old_ndx]->ddname);
new[new_ndx]=index[old_ndx];
}
else /* do not update "new" index, return to the way it was */
{
if(new[new_ndx]==NULL)
Wputf("%3d %-25s",new_ndx+1," ");
else
Wputf("%3d %-25s",new_ndx+1,new[new_ndx]->ddname);
}
Wactiv(old_win); /* reactivate old window */
in_key=0;
break;
} /* end switch */
} /* end if */
} while(in_key != Key_Esc); /* do loop until <esc> pressed */
for(i=0;i<DD_SIZE;i++) /* use indexes built above to build new dialing directory */
{
if(new[i]!=NULL)
memcpy((dial_new+i),new[i],114);
else
memcpy((dial_new+i),index[i],114);
}
if(MouInit) /* turn off mouse cursor */
{
MouLvl=MOU_NONE; /* disable mouse support */
MShide();
}
return(0);
} /* end modify_ddir() */